package com.fancy.social.controller;

import cn.hutool.db.PageResult;
import com.fancy.common.dto.response.Result;
import com.fancy.imasclient.dto.FollowInfoDTO;
import com.fancy.imasclient.dto.FollowRequestDTO;
import com.fancy.social.service.FollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/users")
@Api(tags = "用户社交功能")
@RequiredArgsConstructor
public class UserSocialController {

    private final FollowService followService;

    @PostMapping("/{userId}/follow")
    @ApiOperation("关注用户/歌手")
    public Result<Void> followTarget(@PathVariable Long userId, @RequestBody FollowRequestDTO dto) {
        followService.followTarget(userId, dto);
        return Result.success(null);
    }

    @DeleteMapping("/{userId}/unfollow")
    @ApiOperation("取消关注用户/歌手")
    public Result<Void> unfollowTarget(@PathVariable Long userId, @RequestBody FollowRequestDTO dto) {
        followService.unfollowTarget(userId, dto);
        return Result.success(null);
    }

    @GetMapping("/{userId}/following")
    @ApiOperation("获取关注列表")
    public Result<PageResult<FollowInfoDTO>> getFollowing(@PathVariable Long userId,
                                                         @RequestParam int page,
                                                         @RequestParam int size) {
        PageResult<FollowInfoDTO> result = followService.getFollowing(userId, page, size);
        return Result.success(result);
    }

    @GetMapping("/{userId}/followers")
    @ApiOperation("获取粉丝列表")
    public Result<PageResult<FollowInfoDTO>> getFollowers(@PathVariable Long userId,
                                                         @RequestParam int page,
                                                         @RequestParam int size) {
        PageResult<FollowInfoDTO> result = followService.getFollowers(userId, page, size);
        return Result.success(result);
    }
}
